package com.myccb.app.view.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.myccb.app.AppStatus;
import com.myccb.app.R;
import com.myccb.app.base.RequestManager;
import com.myccb.app.base.BaseActivity;
import com.myccb.app.util.DateTimeUtil;
import com.myccb.app.util.NumberUtil;
import com.myccb.app.widget.CommonToolBar;
import com.myccb.app.widget.EditTextClearable;
import com.myccb.app.widget.LoadingCountdownDialog;
import com.myccb.app.widget.datepicker.CustomDatePicker;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class TransRecordActivity extends BaseActivity {
    private TabLayout tabLayout;
    private RecyclerView recyclerView;
    private TextView BCNumView;
    private TextView balanceView;
    private TextView sumIncomeView;
    private TextView sumOutcomeView;
    private TextView timePeriodView;

    private String fromDateTime = "2017-12-13 17:25:51";
    private String toDateTime = DateTimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss");
    private String toDate = DateTimeUtil.getCurrentDateTime("yyyy-MM-dd");

    private String sumIncome;
    private String sumOutcome;
    private String balance;
    private String BCNum;


    private ArrayList<TransRecordItem> transRecordItemList;

    private LoadingCountdownDialog loadingCountdownDialog;
    private RecyclerViewAdapter recyclerViewAdapter;

    private DrawerLayout drawerLayout;

    private boolean isCreate = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trans_record);
        transRecordItemList = new ArrayList<>();
        initView();
        if (!AppStatus.isLogin) {
            AppStatus.startLoginActivity(this);
        } else
            initData();
        isCreate = true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isCreate && AppStatus.isLogin)
            initData();
     /*   if (isCreate){
            if (!AppStatus.isLogin){
                finish();
                return;
            }
            initData();
        }*/
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == 2)
        {
            if (!data.getStringExtra("status").equals("success"))
                finish();
        }
    }


    private AlertDialog alertDialog;

    private void initView() {


        alertDialog = new AlertDialog.Builder(this).setView(getLayoutInflater().inflate(R.layout.drawerlayout_right_query_trans_record, null)).create();


        CommonToolBar commonToolBar = findViewById(R.id.common_toolbar);

        setSupportActionBar(commonToolBar.getToolbar());

        commonToolBar.setOnLeftButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tabLayout = findViewById(R.id.tabLayout);
        recyclerView = findViewById(R.id.recyclerView);
        BCNumView = findViewById(R.id.BCNum_view);
        balanceView = findViewById(R.id.balance_view);
        sumIncomeView = findViewById(R.id.view_sumIncome);
        sumOutcomeView = findViewById(R.id.view_sumOutcome);
        timePeriodView = findViewById(R.id.time_period_view);

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.addTab(tabLayout.newTab().setText("当天"));
        tabLayout.addTab(tabLayout.newTab().setText("七天"));
        tabLayout.addTab(tabLayout.newTab().setText("一个月"));
        tabLayout.addTab(tabLayout.newTab().setText("更多筛选"));

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                //transRecordItemList.clear();
                //recyclerViewAdapter.notifyDataSetChanged();

                if (tab.getPosition() == 3) {
                    drawerLayout.openDrawer(Gravity.RIGHT);
                    return;
                }

                queryMinAmount = 0;
                queryMaxAmount = Double.MAX_VALUE;
                showTransTypes = 0;
                sortType = -1;
                transRecordItemList.clear();
                switch (tab.getPosition()) {
                    case 0:
                        fromDateTime = toDate + " 00:00:00";
                        timePeriodView.setText(fromDateTime.substring(0, 10).replace("-", "/") + "-" + toDate.replace("-", "/"));
                        new GetTransRecordTask().execute(0);
                        new GetTransRecordTask().execute(1);
                        break;
                    case 1:
                        fromDateTime = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, 0, -7) + " 00:00:00";
                        timePeriodView.setText(fromDateTime.substring(0, 10).replace("-", "/") + "-" + toDate.replace("-", "/"));
                        new GetTransRecordTask().execute(0);
                        new GetTransRecordTask().execute(1);
                        break;
                    case 2:
                        fromDateTime = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, -1, 0) + " 00:00:00";
                        timePeriodView.setText(fromDateTime.substring(0, 10).replace("-", "/") + "-" + toDate.replace("-", "/"));
                        new GetTransRecordTask().execute(0);
                        new GetTransRecordTask().execute(1);
                        break;
                    case 3:
                        //alertDialog.show();
                        break;
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                if (tab.getPosition() == 3) {

                    drawerLayout.openDrawer(Gravity.RIGHT);
                }
            }
        });

        TransRecordItem item = new TransRecordItem();
        item.amount = "999.00";
        item.anotherAccount = "23443343453544554";
        item.balance = "999.00";
        item.time = "2017/09/08 12:09:31";
        item.message = "hello";
        item.date = "2017/09/08";
        item.summary = "转账";
        transRecordItemList.add(item);

        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        recyclerViewAdapter = new RecyclerViewAdapter(this, transRecordItemList);

        recyclerView.setAdapter(recyclerViewAdapter);

        loadingCountdownDialog = new LoadingCountdownDialog(this);


        drawerLayout = findViewById(R.id.trans_record_drawerLayout);
        initDrawerLayout();
    }

    //设置自定义筛选侧边栏

    private RadioGroup rg_queryTimeLine1;
    private RadioGroup rg_queryTimeLine2;

    private RadioGroup rg_showTransTypes;
    private RadioGroup rg_sortType;

    private TextView queryTimeView;

    private TextView rightDrawerOkBtn;
    private TextView rightDrawerResetBtn;


    private EditTextClearable etc_queryMinAmount;
    private EditTextClearable etc_queryMaxAmount;


    private int showTransTypes = 0;
    private int sortType = -1;

    private double queryMinAmount = 0;
    private double queryMaxAmount = Double.MAX_VALUE;


    private TextView selectQueryDateFrom;
    private TextView selectQueryDateTo;

    private CustomDatePicker cdp_queryDateFrom;
    private CustomDatePicker cdp_queryDateTo;


    private String tempFromDate = "2017/12/13";
    private String tempToDate = DateTimeUtil.getCurrentDateTime("yyyy/MM/dd");

    private String tempQueryTime = tempFromDate + "-" + tempToDate;

    private void initDrawerLayout() {


        drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                //rg_queryTimeLine1.check(R.id.query_time_item_one_month);
                //rg_showTransTypes.check(R.id.show_trans_type_all);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }
        });

        ImageView closeDrawerBtn = findViewById(R.id.btn_drawer_close);
        closeDrawerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.closeDrawer(Gravity.RIGHT);
            }
        });

        rg_queryTimeLine1 = findViewById(R.id.query_time_rg_line1);
        rg_queryTimeLine2 = findViewById(R.id.query_time_rg_line2);

        rg_showTransTypes = findViewById(R.id.show_trans_types);
        rg_sortType = findViewById(R.id.sort_type);

        etc_queryMaxAmount = findViewById(R.id.query_max_amount);
        etc_queryMinAmount = findViewById(R.id.query_min_amount);

        selectQueryDateFrom = findViewById(R.id.query_date_from);
        selectQueryDateTo = findViewById(R.id.query_date_to);

        selectQueryDateFrom.setText(tempFromDate.replace("/", "-"));
        selectQueryDateTo.setText(tempToDate.replace("/", "-"));

        selectQueryDateFrom.setEnabled(false);
        selectQueryDateTo.setEnabled(false);

        rg_showTransTypes.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.show_trans_type_all:
                        showTransTypes = 0;
                        break;
                    case R.id.show_trans_type_income:
                        showTransTypes = 1;
                        break;
                    case R.id.show_trans_type_outcome:
                        showTransTypes = -1;
                        break;
                }
            }
        });

        rg_sortType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.sort_type_dec)
                    sortType = -1;
                else
                    sortType = 1;
            }
        });

        queryTimeView = findViewById(R.id.query_time_view);

        rightDrawerOkBtn = findViewById(R.id.right_drawer_btn_ok);
        rightDrawerResetBtn = findViewById(R.id.right_drawer_btn_reset);

        rightDrawerOkBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                timePeriodView.setText(tempQueryTime);
                fromDateTime = tempFromDate.replace("/", "-") + " 00:00:00";
                toDateTime = tempToDate.replace("/", "-") + " 23:59:59";
                transRecordItemList.clear();
                drawerLayout.closeDrawer(Gravity.RIGHT);
                if (etc_queryMaxAmount.getText().toString().equals(""))
                    queryMaxAmount = Double.MAX_VALUE;
                else
                    queryMaxAmount = Double.parseDouble(etc_queryMaxAmount.getText().toString());

                if (etc_queryMinAmount.getText().toString().equals(""))
                    queryMinAmount = 0;
                else
                    queryMinAmount = Double.parseDouble(etc_queryMinAmount.getText().toString());
                new GetTransRecordTask().execute(0);
                new GetTransRecordTask().execute(1);
            }
        });

        rg_queryTimeLine1.setOnCheckedChangeListener(new QueryTimeItemSelectedListener());
        rg_queryTimeLine2.setOnCheckedChangeListener(new QueryTimeItemSelectedListener());

        selectQueryDateFrom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cdp_queryDateFrom = new CustomDatePicker(TransRecordActivity.this, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        selectQueryDateFrom.setText(time.split(" ")[0]);
                        tempFromDate = time.split(" ")[0].replace("-", "/");
                        tempQueryTime = tempFromDate + "-" + tempToDate;
                        queryTimeView.setText(tempQueryTime);
                    }
                }, "2000-01-01 00:00", selectQueryDateTo.getText().toString() + " 00:00");
                cdp_queryDateFrom.showSpecificTime(false); // 不显示时和分
                cdp_queryDateFrom.setIsLoop(false); // 不允许循环滚动
                cdp_queryDateFrom.show(selectQueryDateFrom.getText().toString());
            }

        });

        selectQueryDateTo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cdp_queryDateTo = new CustomDatePicker(TransRecordActivity.this, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        selectQueryDateTo.setText(time.split(" ")[0]);
                        tempToDate = time.split(" ")[0].replace("-", "/");
                        tempQueryTime = tempFromDate + "-" + tempToDate;
                        queryTimeView.setText(tempQueryTime);
                    }
                }, selectQueryDateFrom.getText().toString() + " 00:00", DateTimeUtil.getCurrentDateTime("yyyy-MM-dd HH:mm"));
                cdp_queryDateTo.showSpecificTime(false); // 不显示时和分
                cdp_queryDateTo.setIsLoop(false); // 不允许循环滚动
                cdp_queryDateTo.show(selectQueryDateTo.getText().toString());
            }
        });

        rg_queryTimeLine1.check(R.id.query_time_item_one_month);
        rg_showTransTypes.check(R.id.show_trans_type_all);
        rg_sortType.check(R.id.sort_type_dec);
    }

    private class QueryTimeItemSelectedListener implements RadioGroup.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            selectQueryDateFrom.setEnabled(false);
            selectQueryDateTo.setEnabled(false);
            String queryTime = "";
            if (group != null && checkedId > 0) {
                if (group == rg_queryTimeLine1) {
                    rg_queryTimeLine2.clearCheck();
                    switch (checkedId) {
                        case R.id.query_time_item_one_day:
                            tempFromDate = toDate;// + " 00:00:00";
                            queryTime = tempFromDate.replace("-", "/") + "-" + toDate.replace("-", "/");
                            break;
                        case R.id.query_time_item_a_week:
                            tempFromDate = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, 0, -7);// + " 00:00:00";
                            queryTime = tempFromDate.replace("-", "/") + "-" + toDate.replace("-", "/");
                            break;
                        case R.id.query_time_item_one_month:
                            tempFromDate = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, -1, 0);// + " 00:00:00";
                            queryTime = tempFromDate.replace("-", "/") + "-" + toDate.replace("-", "/");
                            break;
                    }
                } else if (group == rg_queryTimeLine2) {
                    rg_queryTimeLine1.clearCheck();
                    switch (checkedId) {
                        case R.id.query_time_item_three_months:
                            tempFromDate = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, -3, 0);// + " 00:00:00";
                            queryTime = tempFromDate.replace("-", "/") + "-" + toDate.replace("-", "/");
                            break;
                        case R.id.query_time_item_six_months:
                            tempFromDate = DateTimeUtil.addDateTime(toDate, "yyyy-MM-dd", 0, -6, 0);// + " 00:00:00";
                            queryTime = tempFromDate.replace("-", "/") + "-" + toDate.replace("-", "/");
                            break;
                        case R.id.query_time_item_custom:
                            selectQueryDateFrom.setEnabled(true);
                            selectQueryDateTo.setEnabled(true);
                            tempFromDate = selectQueryDateFrom.getText().toString().replace("-", "/");
                            tempToDate = selectQueryDateTo.getText().toString().replace("-", "/");
                            queryTime = tempFromDate + "-" + tempToDate;
                            break;
                    }
                }
                //timePeriodView.setText(queryTime);
                queryTimeView.setText(queryTime);
                tempQueryTime = queryTime;
                group.check(checkedId);
            }

        }

    }


    private void initData() {
        tabLayout.getTabAt(2).select();
    }

    protected class RecyclerViewAdapter extends RecyclerView.Adapter {
        private ArrayList<TransRecordItem> transRecordItems;
        private Context context;

        public RecyclerViewAdapter(Context context, ArrayList transRecordItems) {
            this.context = context;
            this.transRecordItems = transRecordItems;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_transfer_record, parent, false);
            return new TransRecordItemHolder(view);
        }

        @Override
        public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
            if (holder instanceof TransRecordItemHolder) {
                ((TransRecordItemHolder) holder).setContent(transRecordItems.get(position));
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((TransRecordItemHolder) holder).setMoreTransferInfoLayoutVisibility();
                    }
                });
            }
        }

        @Override
        public int getItemCount() {
            return transRecordItems.size();
        }


        private class TransRecordItemHolder extends RecyclerView.ViewHolder {

            TextView amountView;
            TextView balanceView;
            TextView summaryView;
            TextView dayOfWeekView;
            TextView dateView;
            TextView timeView;
            TextView anotherAccountView;
            TextView messageView;
            TextView transferType;
            LinearLayout moreTransferInfoLayout;

            Drawable expend;
            Drawable collapse;

            Drawable pointIncome;
            Drawable pointOutcome;

            public TransRecordItemHolder(View itemView) {
                super(itemView);
                amountView = itemView.findViewById(R.id.view_amount);
                balanceView = itemView.findViewById(R.id.view_balance);
                summaryView = itemView.findViewById(R.id.view_summary);
                dayOfWeekView = itemView.findViewById(R.id.view_day_of_week);
                dateView = itemView.findViewById(R.id.view_date);
                timeView = itemView.findViewById(R.id.view_transfer_time);
                anotherAccountView = itemView.findViewById(R.id.view_another_account);
                messageView = itemView.findViewById(R.id.view_message);
                moreTransferInfoLayout = itemView.findViewById(R.id.transf_info_more);
                transferType = itemView.findViewById(R.id.transfer_type);
                //amountView.setCompoundDrawables();
                expend = getResources().getDrawable(R.mipmap.asset_expand);
                collapse = getResources().getDrawable(R.mipmap.asset_collapse);
                pointIncome = getResources().getDrawable(R.mipmap.u4666);
                pointOutcome = getResources().getDrawable(R.mipmap.u4668);
                expend.setBounds(0, 0, 32, 20);
                collapse.setBounds(0, 0, 32, 20);
                pointIncome.setBounds(0, 0, 16, 16);
                pointOutcome.setBounds(0, 0, 16, 16);
            }

            public void setContent(TransRecordItem transRecordItem) {
                if (transRecordItem.type > 0) {
                    transferType.setText("收入");
                    transferType.setCompoundDrawables(pointIncome, null, null, null);
                    amountView.setTextColor(getResources().getColor(R.color.Pink));
                } else {
                    transferType.setText("支出");
                    transferType.setCompoundDrawables(pointOutcome, null, null, null);
                    amountView.setTextColor(getResources().getColor(R.color.green_500));
                }
                amountView.setText(transRecordItem.amount);
                balanceView.setText(transRecordItem.balance);
                summaryView.setText(transRecordItem.summary);
                dayOfWeekView.setText(DateTimeUtil.dateToWeek(transRecordItem.date));
                dateView.setText(transRecordItem.date);
                timeView.setText(transRecordItem.time);
                anotherAccountView.setText(transRecordItem.anotherAccount);
                messageView.setText(transRecordItem.message);
                amountView.setCompoundDrawables(null, null, collapse, null);
            }

            public void setMoreTransferInfoLayoutVisibility() {
                if (moreTransferInfoLayout.getVisibility() == View.GONE) {
                    moreTransferInfoLayout.setVisibility(View.VISIBLE);
                    amountView.setCompoundDrawables(null, null, expend, null);
                } else {
                    moreTransferInfoLayout.setVisibility(View.GONE);
                    amountView.setCompoundDrawables(null, null, collapse, null);
                }
            }
        }

    }

    protected class TransRecordItem {
        public String date;
        public String time;
        public String amount;
        public String balance;
        public String summary;
        public String anotherAccount;
        public String message;
        public int type;
    }


    private class GetTransRecordTask extends AsyncTask<Integer, Void, Integer> {
        @Override
        protected void onPreExecute() {
            loadingCountdownDialog.show(30);
        }

        @Override
        protected Integer doInBackground(Integer... integers) {


            switch (integers[0]) {
                case 0:
                    getSumTransfer();
                    break;
                case 1:
                    getTimePeriodTransInfoItems();
                    break;
            }


            return null;
        }

        @Override
        protected void onPostExecute(Integer integer) {
            loadingCountdownDialog.dismiss();
            if (sumIncome.equals("null"))
                sumIncome="0.00";
            if (sumOutcome.equals("null"))
                sumOutcome="0.00";

            sumIncomeView.setText(sumIncome);
            sumOutcomeView.setText(sumOutcome);
            balanceView.setText("人民币 " + balance);
            BCNumView.setText(BCNum.substring(0, 4) + "***" + BCNum.substring(BCNum.length() - 4, BCNum.length()));
            //RecyclerView.LayoutManager layoutManager=recyclerView.getLayoutManager();
            //layoutManager.
            recyclerViewAdapter.notifyDataSetChanged();
        }
    }

    private int getSumTransfer() {
        HashMap<String, String> postParams = new HashMap<>();
        postParams.put("action", "getTimePeriodTransInfo");
        postParams.put("fromTime", fromDateTime);
        postParams.put("toTime", toDateTime);
        String result = RequestManager.getInstance(getApplicationContext()).requestSyn("getTransRecord.php", RequestManager.TYPE_POST_FORM, postParams);
        Log.d("register", result);
        JSONObject jb = null;
        try {
            jb = new JSONObject(result);
            int status = jb.getInt("status");
            if (status == 0) {
                int code = jb.getInt("code");

                result = "" + code;
            } else if (status == 1) {
                jb = jb.getJSONObject("result");
                sumIncome = jb.getString("sumIncome");
                sumOutcome = jb.getString("sumOutcome");
                balance = jb.getString("balance");
                BCNum = jb.getString("mainBCNum");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return 0;
    }

    private int getTimePeriodTransInfoItems() {
        HashMap<String, String> postParams = new HashMap<>();
        postParams.put("action", "getTimePeriodTransInfoItems");
        postParams.put("fromTime", fromDateTime);
        postParams.put("toTime", toDateTime);
        postParams.put("sort", "" + sortType);
        Log.d("sortType", "" + sortType);
        String result = RequestManager.getInstance(getApplicationContext()).requestSyn("getTransRecord.php", RequestManager.TYPE_POST_FORM, postParams);
        Log.d("register", result);
        JSONObject jb = null;
        try {
            jb = new JSONObject(result);
            int status = jb.getInt("status");
            if (status == 0) {
                int code = jb.getInt("code");

                result = "" + code;
            } else if (status == 1) {
                //transRecordItemList.clear();
                //jb=jb.getJSONObject("result");
                JSONArray jsonArray = jb.getJSONArray("result");
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONArray row = jsonArray.getJSONArray(i);
                    TransRecordItem item = new TransRecordItem();
                    item.balance = NumberUtil.amountFormat.format(row.getDouble(6));//String.format("%2f",row.getDouble(6));
                    item.type = row.getInt(4);
                    if (item.type * showTransTypes < 0)
                        continue;
                    item.time = row.getString(8);
                    item.date = item.time.substring(0, 10);
                    double amount = row.getDouble(5);
                    if (amount < queryMinAmount || amount > queryMaxAmount)
                        continue;
                    item.amount = NumberUtil.amountFormat.format(amount);//String.format("%2f",row.getDouble(5));
                    item.message = row.getString(7);
                    item.anotherAccount = row.getString(3);
                    transRecordItemList.add(item);
                    switch (item.type) {
                        case 1:
                            item.summary = "转入";
                            break;
                        case -1:
                            item.summary = "转出";
                            break;
                        case -2:
                            item.summary="消费";
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return 0;

    }

}